package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import com.example.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.supervision.SafeControlRecord;
import com.example.ext.entity.ExtSafeControlRecord;
import com.example.service.SafeControlRecordService;

import io.swagger.annotations.ApiOperation;

/**
 * Created by douyx on 2018/03/26.
 */
@RestController
@RequestMapping("api/safeControlRecord")
public class SafeControlRecordController {

	@Autowired
	SafeControlRecordService safeControlRecordService;

	@Autowired
	PromotionService promotionService;
	
	/**
	 * 查询列表的信息
	 * 
	 * @param extSafeControlRecord
	 *                timeFrom:检查日期起(yyyyMMddHHmmss)
	 *                timeTo:检查日期止(yyyyMMddHHmmss)
	 *                checkType:检查类别: 1 日常监督检查 2 专项监督检查
	 *                checkItem:检查类别: 1 设计 2 制造 3 安装 4 改造 5 维修 6 使用 7 气瓶充装 8 经营  9 其他
	 *                dealWay:处理措施: 1 下达监察指令书 2 实施查封 3 实施扣押 4 其他
	 *                usedPartyId:被 检 查单位编号
	 *                advicerId:被检查单位对检查记录的意见提出者编号
	 *                checkerId:检查人员编号
	 * @return
	 */
	@ApiOperation(value = "查询列表的信息", notes = "查询列表的信息")
	@RequestMapping(value = "/getList", method = RequestMethod.POST)
	Map<String, Object> getList(@RequestBody ExtSafeControlRecord extSafeControlRecord) {
		return safeControlRecordService.queryList(extSafeControlRecord);
	}

	@ApiOperation(value = "新增信息", notes = "新增信息")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	Map<String, Object> add(@RequestBody SafeControlRecord safeControlRecord) {
		Map res = safeControlRecordService.add(safeControlRecord);
		Map req = new HashMap();
		req.put("type","2");
		req.put("partyId",safeControlRecord.getUsedPartyId());
		req.put("empiricValue",safeControlRecord.getScore());
		promotionService.addEmpiric(req);
		return res;
	}

	@ApiOperation(value = "更新信息", notes = "更新信息")
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	Map<String, Object> update(@RequestBody SafeControlRecord safeControlRecord) {
		return safeControlRecordService.update(safeControlRecord);
	}

	@ApiOperation(value = "更新检查人员的信息", notes = "更新检查人员的信息")
	@RequestMapping(value = "/updateChecker", method = RequestMethod.POST)
	Map<String, Object> updateChecker(@RequestBody SafeControlRecord safeControlRecord) {
		return safeControlRecordService.updateChecker(safeControlRecord);
	}

	@ApiOperation(value = "更新执法文书", notes = "更新执法文书")
	@RequestMapping(value = "/uploadDocs", method = RequestMethod.POST)
	Map<String, Object> uploadDocs(@RequestBody SafeControlRecord safeControlRecord) {
		return safeControlRecordService.uploadDocs(safeControlRecord);
	}

	@ApiOperation(value = "更新行政处罚书", notes = "更新行政处罚书")
	@RequestMapping(value = "/updateSafePunDoc", method = RequestMethod.POST)
	Map<String, Object> uploadPunDocs(@RequestBody SafeControlRecord safeControlRecord) {
		return safeControlRecordService.uploadPunDocs(safeControlRecord);
	}

	@ApiOperation(value = "更新证据", notes = "更新证据")
	@RequestMapping(value = "/updateSafeEvidences", method = RequestMethod.POST)
	Map<String, Object> uploadEvidences(@RequestBody SafeControlRecord safeControlRecord) {
		return safeControlRecordService.uploadEvidences(safeControlRecord);
	}

	@ApiOperation(value = "查询信息", notes = "查询信息")
	@RequestMapping(value = "/getOne/{id}", method = RequestMethod.POST)
	Map<String, Object> queryById(@PathVariable String id) {
		return safeControlRecordService.queryById(id);
	}

	@ApiOperation(value = "导出信息", notes = "导出信息")
	@RequestMapping(value = "/export/{id}", method = RequestMethod.POST)
	Map<String, Object> export(@PathVariable String id) {
		return safeControlRecordService.export(id);
	}
}
